class Room(breve.Real):
	def __init__(self, dim, unit, botList):
		breve.Real.__init__(self)
		self.unit = unit
		self.width = dim[0]
		self.height = dim[2]
		self.getController().pointCamera(
			breve.vector(self.width * unit / 2, 0, -self.height * unit / 2), 
			breve.vector(0, 100, self.height * unit))
		self.getController().moveLight(
			breve.vector(self.width * unit / 2, 10, -self.height * unit / 2))
		
		for x in range(0, self.width):
			Wall(breve.vector(x * unit + unit / 2, unit / 2, 0), 
				 breve.vector(unit, unit, .1))
			Wall(breve.vector(x * unit + unit / 2, unit / 2, -self.height * unit), 
				 breve.vector(unit, unit, .1))
		
		for z in range(0, self.height):
			Wall(breve.vector(0, unit / 2, -z * unit - unit / 2), 
				 breve.vector(.1, unit, unit))
			Wall(breve.vector(self.width * unit, unit / 2, -z * unit - unit / 2), 
				 breve.vector(.1, unit, unit))

		for z in range(0, self.height):
			for x in range(0, self.width):
				Ground(breve.vector(x * unit + unit / 2, 0, -z * unit - unit / 2), 
					   breve.vector(unit, .1, unit))
		
		if len(botList) > self.width * self.height:
			print "Too many bots!"
		self.placeBots(botList)	
		
	def placeBots(self, botList):
		positions = []
		positionCount = self.width * self.height
		
		for i in range(0, positionCount):
			positions.append(True)

		while len(botList) > 0:
			while True:
				spot = random.randint(0, positionCount - 1)
				if positions[spot]: break
				
			positions[spot] = False	
			bot = botList.pop()
			bot.setNeighborhoodSize(self.unit * 2)
			bot.move(breve.vector(int(spot % self.height) * self.unit + self.unit / 2, self.unit / 2, 
								 -int(spot / self.height) * self.unit - self.unit / 2))

	def getWidth(self): return self.width
	def getHeight(self): return self.height
	def getUnit(self): return self.unit
	
class Obstruction(breve.Stationary):
	def __init__(self, position, dimension, color):
		breve.Stationary.__init__(self)
		self.setTexture(-1)
		self.setShape(breve.createInstances(breve.Cube, 1).initWith(dimension))
		self.setColor(color)
		self.move(position)
	
class Wall(Obstruction):
	def __init__(self, position, dimension):
		Obstruction.__init__(self, position, dimension, breve.vector(1.0, 1.0, 1.0))
		self.setBitmapTransparency(0.5)	
		
class Ground(Obstruction):
	def __init__(self, position, dimension):
		Obstruction.__init__(self, position, dimension, breve.vector(0.0, 0.3, 0.0))
		self.setBitmapTransparency(0.5)